import { getGameObjectById } from "../engine";
import { Behaviour } from "../engine/Behaviour";
import { Transform } from "../engine/Transform";
import { number } from "../engine/validators/number";
import { ItemSpeed } from "./ItemSpeed";
import { Walkable } from "./Walkable";

export class MenuWalkable extends Behaviour {
    private currentSpeed = 0;
    @number()
    walkspeed = 2;
    ClickFlag=1;

    onStart() {

        this.gameObject.onClick = () => {
             console.log(this.gameObject.id);
            if(this.gameObject.id=="UI_button_menu"){
              this.ClickFlag+=1;
              if(getGameObjectById('UI_button_settings').getBehaviour(ItemSpeed).speed==0
              &&getGameObjectById('UI_button_restart').getBehaviour(ItemSpeed).speed==0
              &&getGameObjectById('UI_button_quit').getBehaviour(ItemSpeed).speed==0
               )  {
                this.currentSpeed=this.walkspeed;
              }else{
               this.currentSpeed=0;
              }
            }

        };
    }

    onTick(duringTime: number) {
        const SettingTransform = getGameObjectById('UI_button_settings').getBehaviour(Transform);
        const RestartTransform = getGameObjectById('UI_button_restart').getBehaviour(Transform);
        const QuitTransform = getGameObjectById('UI_button_quit').getBehaviour(Transform);

        if(this.ClickFlag%2==0){
            if(SettingTransform.y<=50){
                SettingTransform.y += this.currentSpeed;
           }else{
               SettingTransform.y += 0;
           }
          
           if(RestartTransform.y<=90){
               RestartTransform.y += this.currentSpeed;
           }else{
               RestartTransform.y+=0;
           }
   
           if(QuitTransform.y<=130){
               QuitTransform.y+=this.currentSpeed;
           }else{
               QuitTransform.y+=0;
           }
        }else{
            if(SettingTransform.y>7){
                SettingTransform.y -= this.currentSpeed;
           }else{
               SettingTransform.y -= 0;
           }
          
           if(RestartTransform.y>7){
               RestartTransform.y -= this.currentSpeed;
           }else{
               RestartTransform.y-=0;
           }
   
           if(QuitTransform.y>7){
               QuitTransform.y-=this.currentSpeed;
           }else{
               QuitTransform.y-=0;
           }
        }


        
       
    }
}
